package com.qtenv.datasync.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qtenv.datasync.service.entity.TerminalsFreeze;
import com.qtenv.datasync.service.mapper.TerminalsFreezeMapper;
import com.qtenv.datasync.service.service.TerminalsFreezeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 大表日冻结数据表（设备维度） 服务实现类
 * </p>
 *
 * @author CBL
 * @since 2022-08-05
 */
@Service
public class TerminalsFreezeServiceImpl extends ServiceImpl<TerminalsFreezeMapper, TerminalsFreeze> implements TerminalsFreezeService {

    @Override
    public List<TerminalsFreeze> getTerminalUsageDataList(String tenantId, String terminalId) {
        LocalDate yesterday = LocalDate.now().minusDays(1);
        LocalDate aMonthAgo = LocalDate.now().minusMonths(1);
        return this.list(new QueryWrapper<TerminalsFreeze>().eq("tenant_id", tenantId).eq("TerminalID", terminalId)
                .between("FreezeTime", aMonthAgo.toString(), yesterday.toString()));
    }
}
